<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
//商品详情控制器
class DetailController extends Controller{
	//首页
	public function index(){
		$goodsdata=Db::table('goods')
					//关联商品详细表
				 ->join('detail','goods_gid','=','gid')
				 ->where("gid=" . Q('get.gid',0,'intval'))
				 ->get();
				 //sp($goodsdata);exit;
		 foreach ($goodsdata as $k=>$v){
		 	//图册转数组
		 	$combine=explode(',', $v['big']);
		 	$goodsdata[$k]['big']=$combine;
 			//sp($goodsdata);exit;
		 }
		 $gid=Q('get.gid',0,'intval');
		 //sp($gid);
		 $data=Db::table('goods_attr')
					//关联商品属性表
				 ->join('typeAttribute','typeAttribute_aid','=','aid')
				 ->where('goods_gid',$gid)
				 ->where('attrtyoe',1)
				 ->groupBy('gtid')
				 ->orderBy('gtid','asc')
				 ->get();
				 //sp($data);exit;
				 foreach($data as $k=>$v){
					$data[$k]['son']=Db::table('goods_attr')
							->join('typeAttribute','typeAttribute_aid','=','aid')
							->where('goods_gid',$gid)
							->where('aid',$v['aid'])
							->where('attrtyoe',1)
							->orderBy('gtid','asc')
							->get();
							
				}
//				sp($data);exit;
				 $datas=Db::table('goods_attr')
					//关联商品属性表
				 ->join('typeAttribute','typeAttribute_aid','=','aid')
				 ->where('goods_gid',$gid)
				 ->where('attrtyoe',0)
				 ->groupBy('gtid')
				 ->orderBy('gtid','asc')
				 ->get();
//				 sp($datas);exit;
		View::with('data',$data);	
		View::with('datas',$datas);
		View::with('goodsdata',$goodsdata);
		$cateModel=new \Common\Model\Cate;
		$cateData=$cateModel->get();
		View::with('cateData',$cateData);

		View::make();
}
	public function add(){
		sp(Q('post.price'));
		$data = array();
		$combine = implode(',', Q('post.combine'));
		
		$attrData = Db::table('goods_attr')
							->where("gattrid in (".$combine.")")
							->sum('append');
		$data ['add_price'] = Q('post.price') + $attrData;
							
		$inv = Db::table('goods_list')
				->where("grou='$combine'")
				->pluck('inventory');
		$data['inv'] = $inv;
		$this->ajax($data);

	}
	public function addData(){
		$shopData=array(
				'id'=>Q('post.aid'),
				'name'=>Q('post.aname'),
				'num'=>Q('post.num'),
				'price'=>Q('post.shopprice'),				
		);	
		Cart::add($shopData);
	}
}
